#include "delay.h"
#include "sys.h"
#include "led.h"
#include "lcd_1602.h"

u8 ViewData1[16] = { "1234567890123456" };
u8 ViewData2[16] = { "ABCDEFGHIJKLMNOP" };

u8 ViewData3[16] = { "V: 10.0000000 mV" };
u8 ViewData4[16] = { "R:  9.9999999 Ko" };

unsigned char strTemp4[4];
unsigned char *tr_4(unsigned int data)
{
    strTemp4[0] = (unsigned char)(((data / 1000) % 10) + 0x30);
    strTemp4[1] = (unsigned char)(((data / 100) % 10) + 0x30);
    strTemp4[2] = (unsigned char)(((data / 10) % 10) + 0x30);
    strTemp4[3] = (unsigned char)((data % 10) + 0x30);
    return strTemp4;
}

int main(void)
{
    u8 i;
    int v;
    unsigned char *chars;

    Delay_Init();
    NVIC_Configuration();
    LED_Init();

    for(i = 0; i < 8; i++)
    {
        LED0 = 0;
        Delay_Ms(30);
        LED0 = 1;
        Delay_Ms(30);
    }

    LCD1602_GPIO_Configuration();
    LCD1602_Init();
    Delay_Ms(500);

    while (1)
    {
        for (i = 0; i < 16; i++)
        {
            LCD1602_Set_Cursor(i, 0);
            LCD1602_Write_Data(ViewData1[i]);
        }

        for (i = 0; i < 16; i++)
        {
            LCD1602_Set_Cursor(i, 1);
            LCD1602_Write_Data(ViewData2[i]);
        }

        Delay_Ms(5000);

        for (i = 0; i < 16; i++)
        {
            LCD1602_Set_Cursor(i, 0);
            LCD1602_Write_Data(ViewData3[i]);
        }

        for (i = 0; i < 16; i++)
        {
            LCD1602_Set_Cursor(i, 1);
            LCD1602_Write_Data(ViewData4[i]);
        }

        Delay_Ms(2000);

        for (v = 1000; v < 3999; v++)//测试快速递增的数字的显示
        {
            LCD1602_Set_Cursor(9, 0);
            chars = tr_4(v);
            for (i = 0; i < 4; i++)
            {
                LCD1602_Write_Data(chars[i]);
            }
        }

        for (v = 9999; v > 6999; v--)//测试快速递增的数字的显示
        {
            LCD1602_Set_Cursor(9, 1);
            chars = tr_4(v);
            for (i = 0; i < 4; i++)
            {
                LCD1602_Write_Data(chars[i]);
            }
        }

        Delay_Ms(1000);
    }
}

